package com.xbongbong.saas.service.impl;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.distributor.dto.DistributorEditAttrUpdateDTO;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.constant.MessageConstant;
import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.domain.entity.PaasFormDataEntity;
import com.xbongbong.paas.domain.entity.PaasFormExplainEntity;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.PlatFormEnum;
import com.xbongbong.paas.help.ProSaveHelp;
import com.xbongbong.paas.help.subform.DistributorAccountTransferSubForm;
import com.xbongbong.paas.log.MongoLogHelp;
import com.xbongbong.paas.log.constant.LogMemoConstant;
import com.xbongbong.paas.log.pojo.InfoArrPojo;
import com.xbongbong.paas.model.PaasFormExplainModel;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.AttrValuePojo;
import com.xbongbong.paas.pojo.ButtonPojo;
import com.xbongbong.paas.pojo.DataDetailPojo;
import com.xbongbong.paas.pojo.DetailTabPojo;
import com.xbongbong.paas.pojo.DetailTitlePojo;
import com.xbongbong.paas.pojo.FieldAttrEntityForImport;
import com.xbongbong.paas.pojo.FormTitlePoJo;
import com.xbongbong.paas.pojo.SmsSpacePojo;
import com.xbongbong.paas.pojo.SummaryDataPoJo;
import com.xbongbong.paas.pojo.WorkFlowPojo;
import com.xbongbong.paas.pojo.dto.FormDataAddDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.ImportFormDataDTO;
import com.xbongbong.paas.pojo.dto.SaasFormSaveDTO;
import com.xbongbong.paas.pojo.dto.ValidateDataDTO;
import com.xbongbong.paas.pojo.imports.CellTitlePojo;
import com.xbongbong.paas.pojo.imports.CellValuePojo;
import com.xbongbong.paas.pojo.imports.RowGroupPojo;
import com.xbongbong.paas.redis.PaasRedisHelper;
import com.xbongbong.paas.redis.RedisPrefixConstant;
import com.xbongbong.paas.service.SMSSpaceService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.paas.toolbox.util.RegexUtil;
import com.xbongbong.paas.toolbox.util.StringUtil;
import com.xbongbong.paas.toolbox.wrap.UserVO;
import com.xbongbong.paas.util.ExplainUtil;
import com.xbongbong.pro.applist.pojo.AppListPojo;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.config.ProBaseConfig;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.ValueAddedTypeEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.formdata.pojo.dto.FormDataDetailDTO;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.pro.formdata.pojo.vo.FormDataDetailVO;
import com.xbongbong.saas.constant.BasicConstant;
import com.xbongbong.saas.constant.ErrorMessageConstant;
import com.xbongbong.saas.domain.entity.DistributorAccountEntity;
import com.xbongbong.saas.enums.BusinessDetailButtonEnum;
import com.xbongbong.saas.enums.BusinessDetailTabEnum;
import com.xbongbong.saas.enums.OperateModuleTypeEnum;
import com.xbongbong.saas.enums.OperateTypeEnum;
import com.xbongbong.saas.enums.SaasButtonEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.DistributorAccountEnum;
import com.xbongbong.saas.help.ImportHelper;
import com.xbongbong.saas.help.LogHandleHelp;
import com.xbongbong.saas.help.SaasSaveHelp;
import com.xbongbong.saas.model.DistributorAccountModel;
import com.xbongbong.saas.service.DistributorAccountService;
import com.xbongbong.saas.toolbox.help.FastJsonHelper;
import com.xbongbong.sys.domain.entity.CompanyEntity;
import com.xbongbong.sys.domain.entity.FeeLogEntity;
import com.xbongbong.sys.model.CompanyModel;
import com.xbongbong.sys.model.FeeLogModel;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 *
 * @author xinpeng.jiang
 * @date 2020/12/22 15:59
 * @version 1.0
 * @since V1.0
 */
@Service("distributorAccountService")
public class DistributorAccountServiceImpl implements DistributorAccountService {

    @Resource
    private SaasSaveHelp saasSaveHelp;
    @Resource
    private DistributorAccountModel distributorAccountModel;
    @Resource
    private PaasFormExplainModel paasFormExplainModel;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private MongoLogHelp mongoLogHelp;
    @Resource
    private DistributorAccountTransferSubForm distributorAccountTransferSubForm;
    @Resource
    private ImportHelper importHelper;
    @Resource
    private FeeLogModel feeLogModel;
    @Resource
    private CompanyModel companyModel;
    @Resource
    private PaasRedisHelper paasRedisHelper;
    @Resource
    private LogHandleHelp logHandleHelp;

    private static final Logger LOG = LoggerFactory.getLogger(DistributorAccountServiceImpl.class);

    private static final String MSG = "%s尊敬的%s，%s邀请你成为%s的商业合作伙伴。请在微信小程序中搜索“销帮帮经销宝D”，或在电脑端点击链接。%s";


    @Override
    public void formatAddExplain(FormatExplainDTO formatExplainDTO) throws XbbException {
    }

    @Override
    public void beforeSave(ValidateDataDTO validateDataDTO) throws XbbException {
        JSONObject data = validateDataDTO.getData();
        Long dataId = validateDataDTO.getDataId();
        String corpid = validateDataDTO.getCorpid();
        String phone = data.getString(DistributorAccountEnum.PHONE.getAttr());
        String name = data.getString(DistributorAccountEnum.NAME.getAttr());
        String phoneName = validateDataDTO.getExplainMap().get(DistributorAccountEnum.PHONE.getAttr()).getAttrName();
        String nameName = validateDataDTO.getExplainMap().get(DistributorAccountEnum.NAME.getAttr()).getAttrName();
        // 格式化关联客户
        saasSaveHelp.formatLinkBusiness4Save(data, DistributorAccountEnum.DISTRIBUTOR_NAME.getAttr(), DistributorAccountEnum.DISTRIBUTOR_NAME_LINK_TEXT.getAttr(), DistributorAccountEnum.DISTRIBUTOR_NAME.getFieldType());
        // 启用的账号需要校验
        if (Objects.equals(data.getInteger(DistributorAccountEnum.ACCOUNT_STATUS.getAttr()), 1) || Objects.isNull(dataId) || Objects.equals(dataId, 0L)) {
            boolean repeat = distributorAccountModel.phoneRepeat(corpid, phone, dataId);
            if (repeat) {
                throw new  XbbException(SystemErrorCodeEnum.API_ERROR_100006.getCode(), ErrorMessageConstant.NO_REPEAT, phoneName);
            }
        }
        if (StringUtil.isNotEmpty(name) && name.length() > 50) {
            throw new  XbbException(SystemErrorCodeEnum.API_ERROR_100006.getCode(), ErrorMessageConstant.MORE_THAN_FIFTY, nameName);
        }
        if (StringUtil.isNotEmpty(phone) && phone.length() > 50) {
            throw new  XbbException(SystemErrorCodeEnum.API_ERROR_100006.getCode(), ErrorMessageConstant.MORE_THAN_FIFTY, phoneName);
        }
        // TODO 套餐校验
        boolean overPackage = isOverPackage(corpid, Collections.singletonList(data.getLong(DistributorAccountEnum.DISTRIBUTOR_NAME.getAttr())));
        if (overPackage) {
            throw new  XbbException(SystemErrorCodeEnum.API_ERROR_100074);
        }
    }

    @Override
    public boolean isOverPackage(String corpid, List<Long> idList) throws XbbException {
        List<FeeLogEntity> feeLogEntities = feeLogModel.getByType(corpid, ValueAddedTypeEnum.DISTRIBUTOR.getType());
        List<Long>  distributorIdList = distributorAccountModel.getDistributorAccountNum(corpid);
        Integer num = distributorIdList.size();
        for (Long item : idList) {
            if (!distributorIdList.contains(item)) {
                num++;
            }
        }
        boolean overPackage = false;
        if (feeLogEntities.isEmpty()) {
            overPackage = true;
        } else {
            Long maxTime = 0L;
            Integer maxNum = 0;
            for (FeeLogEntity item : feeLogEntities) {
                if (Objects.nonNull(item.getEndTime()) && item.getEndTime() > maxTime) {
                    maxTime = item.getEndTime();
                    maxNum = item.getSumValue();
                }
            }
            if (maxTime < DateTimeUtil.getInt() || maxNum < num) {
                overPackage = true;
            }
        }
        return overPackage;
    }

    @Override
    public void afterSave(SaasFormSaveDTO saasFormSaveDTO) throws XbbException {
        boolean isNew = saasFormSaveDTO.getIsNew();
        PaasFormDataEntity paasFormDataEntity = saasFormSaveDTO.getNewPaasFormDataEntity();
        paasFormDataEntity.setAddTime(DateTimeUtil.getInt());
        paasFormDataEntity.setUpdateTime(DateTimeUtil.getInt());
        JSONObject data = saasFormSaveDTO.getNewData();
        String corpid = saasFormSaveDTO.getCorpid();
        Long distributorId = data.getLong(DistributorAccountEnum.DISTRIBUTOR_NAME.getAttr());
        if (isNew) {
            DistributorAccountEntity distributorAccountEntity = distributorAccountTransferSubForm.transferFormDataToEntity(paasFormDataEntity);
            Integer sort = distributorAccountModel.getMaxSort(corpid, distributorId);
            sort = Objects.isNull(sort) ? 0 : sort;
            distributorAccountEntity.setSort(++sort);
            distributorAccountEntity.setEnable(1);
            distributorAccountModel.insert(distributorAccountEntity);
            // TODO 短信 日志 消息
            String creatorName = saasFormSaveDTO.getLoginUserName();
            String accountName = distributorAccountEntity.getName();
            CompanyEntity companyEntity = companyModel.getByKey(corpid);
            String corpName = companyEntity.getCorpName();
            // 套餐缓存移除
            paasRedisHelper.removeValue(RedisPrefixConstant.VALUE_ADDED, corpid + "_" + ValueAddedTypeEnum.DISTRIBUTOR.getType());
            try {
                if (RegexUtil.isMobile(distributorAccountEntity.getPhone())) {
                    SmsSpacePojo sms = SMSSpaceService.sendNoticeSMS(distributorAccountEntity.getPhone(), String.format(MSG, SMSSpaceService.XBB_PREFIX, accountName, creatorName, corpName, ProBaseConfig.getDistributorLoginUrl()), "1");
                    LOG.warn(JSON.toJSONString(sms));
                }
            } catch (XbbException e) {
                LOG.error("经销商新建账号短信发送异常", e);
            }
        } else {
            PaasFormDataEntity oldPaasFormData = saasFormSaveDTO.getOldPaasFormDataEntity();
            DistributorAccountEntity distributorAccountEntity = distributorAccountTransferSubForm.transferFormDataToEntity(oldPaasFormData);
            distributorAccountEntity.setUpdateTime(paasFormDataEntity.getUpdateTime());
            distributorAccountEntity.setName(data.getString(DistributorAccountEnum.NAME.getAttr()));
            distributorAccountEntity.setRole(data.getString(DistributorAccountEnum.AUTHORITY.getAttr()));
            distributorAccountModel.update(distributorAccountEntity);
            paasRedisHelper.removeHashValue(RedisPrefixConstant.DISTRIBUTOR_XBB_ACCESS_TOKEN, corpid, distributorAccountEntity.getId().toString());
        }

    }

    @Override
    public FormDataDetailVO getWebDetail(FormDataDetailDTO formDataDetailDTO) throws XbbException {
        FormDataDetailVO formDataDetailVO = new FormDataDetailVO();
        String corpid = formDataDetailDTO.getCorpid();
        DistributorAccountEntity distributorAccountEntity = distributorAccountModel.getByKey(formDataDetailDTO.getDataId(), corpid);
        if (distributorAccountEntity == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_DATA_NOT_EXIST);
        }
        //
        PaasFormExplainEntity paasFormExplainEntity = paasFormExplainModel.getByBusinessType4Distributor(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(), corpid, DistributorMarkEnum.DISTRIBUTOR.getCode());
        if (paasFormExplainEntity == null) {
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, MessageConstant.FORM_DATA_NOT_EXIST);
        }
        Long formId = paasFormExplainEntity.getFormId();
        PaasFormEntityExt paasFormEntityExt = paasFormModel.getByKey(formId, corpid);
        formDataDetailVO.setTab(getDetailTabPojos(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getCode(),formDataDetailDTO.getLoginUser(),PlatFormEnum.WEB));
        formDataDetailVO.setPaasFormEntityExt(paasFormEntityExt);
        //副标题
        JSONArray secondTitle = new JSONArray();
        secondTitle.add(ExplainUtil.getSecondTitleObj(false, DistributorAccountEnum.DISTRIBUTOR_NAME.getAttrName(), "",""));
        secondTitle.add(ExplainUtil.getSecondTitleObj(false, DistributorAccountEnum.AUTHORITY.getAttrName(), "",""));
        secondTitle.add(ExplainUtil.getSecondTitleObj(false, DistributorAccountEnum.ADD_TIME.getAttrName(), "",""));
        //头部信息（包含操作）
        DataDetailPojo dataDetailPojo = new DataDetailPojo();
        //标题
        DetailTitlePojo title = new DetailTitlePojo();
        title.setName(distributorAccountEntity.getName());
        dataDetailPojo.setTitle(title);
        dataDetailPojo.setSecondTitle(secondTitle);
        //
        List<WorkFlowPojo> workFlowPojoList = new ArrayList<>();
        dataDetailPojo.setWorkFlow(workFlowPojoList);
        //按钮
        ButtonPojo buttonPojo = new ButtonPojo();
        SaasButtonEnum saasButtonEnum = BusinessDetailButtonEnum.DISTRIBUTOR_CONTACT_EDIT.getAnEnum();
        BeanUtil.copyProperties(saasButtonEnum, buttonPojo);
        List<ButtonPojo> buttonPojoList = new ArrayList<>();
        buttonPojoList.add(buttonPojo);
        dataDetailPojo.setButton(buttonPojoList);
        dataDetailPojo.setTags(new JSONArray());
        dataDetailPojo.setTabSortPermission(true);
        dataDetailPojo.setDial(new ArrayList<>());
        formDataDetailVO.setHead(dataDetailPojo);
        return formDataDetailVO;
    }

    @Override
    public void formatData(SaasAnalysisDataDTO saasAnalysisDataDTO, JSONObject result) throws XbbException {
        distributorAccountModel.formatData(saasAnalysisDataDTO, result);
    }

    @Override
    public void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException {
        distributorAccountModel.formatUpdateExplain(formatExplainDTO);
    }

    @Override
    public void batchEditAttr(DistributorEditAttrUpdateDTO distributorEditAttrUpdateDTO) throws XbbException {
        try {
            String userId = distributorEditAttrUpdateDTO.getUserId();
            String corpid = distributorEditAttrUpdateDTO.getCorpid();
            String loginUserName = distributorEditAttrUpdateDTO.getLoginUserName();
            List<Long> idIn = distributorEditAttrUpdateDTO.getDataIdList();
            List<DistributorAccountEntity> distributorAccountEntities = distributorAccountModel.getByIdIn(corpid, idIn);
            if (Objects.isNull(distributorAccountEntities)) {
                throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
            }
            // 批量编辑日志
            List<String> updataItemList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
            List<Long> dataIdList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);

            AttrValuePojo singleAttrValuePojo = ProSaveHelp.getSingleAttrValuePojo(distributorEditAttrUpdateDTO.getIsFieldDependence(), distributorEditAttrUpdateDTO.getFieldEditedList());
            for (DistributorAccountEntity item : distributorAccountEntities) {
                if (Objects.equals(singleAttrValuePojo.getAttr(), DistributorAccountEnum.NAME.getAttr())) {
                    item.setName(Objects.toString(singleAttrValuePojo.getValue()));
                } else if (Objects.equals(singleAttrValuePojo.getAttr(), DistributorAccountEnum.AUTHORITY.getAttr())) {
                    item.setRole(Objects.toString(singleAttrValuePojo.getValue()));
                }
                dataIdList.add(item.getId());
                String opObjectName = item.getName();
                updataItemList.add(opObjectName);
            }
            String updataItem = StringUtils.join(updataItemList, "，");
            distributorAccountModel.updateBatch(distributorAccountEntities);

            String changedLogItemsStr = logHandleHelp.getChangedLogItemsStr(distributorEditAttrUpdateDTO.getLogFieldEditedList());
            if(dataIdList.size() > 1 ){
                String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_UPDATE_FORM_DATA_BATCH_ATTR), loginUserName, XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getName(),
                        changedLogItemsStr, dataIdList.size());
                List<InfoArrPojo> infoArrPojoList = new ArrayList<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
                InfoArrPojo infoArrPojo = new InfoArrPojo();
                infoArrPojo.setTitle(XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getName());
                infoArrPojo.setContent(updataItem);
                infoArrPojoList.add(infoArrPojo);
                mongoLogHelp.buildLog4InfoArr(infoArrPojoList, corpid, userId, loginUserName, OperateModuleTypeEnum.DISTRIBUTOR_ACCOUNT, OperateTypeEnum.EDIT,
                        "", "", memo, distributorEditAttrUpdateDTO.getHttpHeader());
            } else if (Objects.equals(dataIdList.size(), 1)) {
                String memo = String.format(I18nMessageUtil.getMessage(LogMemoConstant.LOG_MEMO_USER_UPDATE_FORM_DATA_ATTR), loginUserName, XbbRefTypeEnum.DISTRIBUTOR_ACCOUNT.getName(), updataItem,
                        changedLogItemsStr);
                mongoLogHelp.buildLog(corpid, userId, loginUserName, OperateModuleTypeEnum.DISTRIBUTOR_ACCOUNT, OperateTypeEnum.EDIT,
                        dataIdList.get(0).toString(), updataItem, memo, distributorEditAttrUpdateDTO.getHttpHeader());
            }
        } catch (XbbException e) {
            throw e;
        } catch (Exception e) {
            LOG.error("contactServiceImpl.batchEditAttr 执行出错：", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
    }

    @Override
    public ListAppVO formatAccountAppList(FormDataListDTO formDataListDTO, List<PaasFormDataEntityExt> esEntities, Integer totalCount) throws XbbException {
        List<AppListPojo> appListPojos = new ArrayList<>();
        String corpid = formDataListDTO.getCorpid();
        Long formId = formDataListDTO.getFormId();

        for (PaasFormDataEntityExt entity : esEntities) {
            JSONObject data = entity.getData();
            Long id = entity.getDataId();
            JSONObject superScript = new JSONObject();
            JSONObject others = new JSONObject();
            others.put("status", entity.getData().getString(DistributorAccountEnum.ACCOUNT_STATUS.getAttr()));
            List<SummaryDataPoJo> summaryList = FastJsonHelper.getJsonArrOrDefaultFromFormData(data, BasicConstant.SUMMARY_LIST, new JSONArray()).toJavaList(SummaryDataPoJo.class);
            List<SummaryDataPoJo> lablesList = FastJsonHelper.getJsonArrOrDefaultFromFormData(data, BasicConstant.LABELS_LIST, new JSONArray()).toJavaList(SummaryDataPoJo.class);
            List<FormTitlePoJo> titleList = FastJsonHelper.getJsonArrOrDefaultFromFormData(data, BasicConstant.TITLE_LIST, new JSONArray()).toJavaList(FormTitlePoJo.class);
            appListPojos.add(new AppListPojo(id, titleList, summaryList, superScript, lablesList, others, entity.getAppId(), entity.getMenuId(), entity.getFormId()));
        }
        ListAppVO listAppVO = new ListAppVO();
        listAppVO.setList(appListPojos);
        listAppVO.setTotalCount(totalCount);
        return  listAppVO;
    }

    @Override
    public void setDistributorName(List<PaasFormDataEntityExt> paasFormDataESList, String corpid) {
        distributorAccountModel.setDistributorName(paasFormDataESList, corpid);
    }

    @Override
    public FormDataAddDTO formatExcelValue(ImportFormDataDTO importFormDataDTO, List<CellTitlePojo> titlePojoList, RowGroupPojo rowGroupPojo, List<FieldAttrEntityForImport> fieldAttrList) throws XbbException {
        FormDataAddDTO formDataAddDTO = new FormDataAddDTO();
        BeanUtil.copyProperties(importFormDataDTO, formDataAddDTO);
        formDataAddDTO.setSerialNo("");
        JSONObject dataJson = new JSONObject();
        List<List<CellValuePojo>> rowValueList = rowGroupPojo.getRowValueList();
        // 分组的第一条数据作为给实体对象赋值的数据
        List<CellValuePojo> cellValueList = rowValueList.get(0);
        for (FieldAttrEntityForImport fieldAttr : fieldAttrList) {
            String attr = fieldAttr.getAttr();
            Integer fieldType = fieldAttr.getFieldType();
            String attrName = fieldAttr.getAttrName();
            Integer columnIndex = importHelper.getColumnIndexByTitle(titlePojoList, attrName, null);
            Object cellValue = importHelper.getValueByColumnIndex(cellValueList, columnIndex);
            if (Objects.equals(fieldType, FieldTypeEnum.SUB_FORM.getType())) {
                importHelper.formatSubFormValue4Import(rowValueList, titlePojoList, importFormDataDTO, fieldAttr, dataJson);
            } else {
                if (Objects.isNull(cellValue) || StringUtil.isEmpty(cellValue.toString())) {
                    continue;
                }
                if (ImportHelper.commonHandleFieldType.contains(fieldAttr.getFieldType())) {
                    importHelper.formatCommonField(dataJson, fieldAttr, cellValue);
                } else if (Objects.equals(fieldType, FieldTypeEnum.SERIALNO.getType())) {
                    formDataAddDTO.setSerialNo(cellValue.toString());
                } else if (Objects.equals(fieldType, FieldTypeEnum.LINK_DATA.getType())) {
                    importHelper.formatLinkData(cellValue, fieldAttr, dataJson);
                } else if (Objects.equals(fieldType, FieldTypeEnum.LINK_DATA_MULTI.getType())) {
                    importHelper.formatLinkDataMulti(cellValue, importFormDataDTO, fieldAttr, dataJson);
                } else {
                    dataJson.put(attr, cellValue);
                }
            }
        }
        formDataAddDTO.setDataList(dataJson);
        return formDataAddDTO;
    }

    private List<DetailTabPojo> getDetailTabPojos(Integer businessType, UserVO userVO, PlatFormEnum platFormEnum) {
        List<BusinessDetailTabEnum> tabEnumList;
        if (Objects.equals(platFormEnum, PlatFormEnum.WEB)) {
            tabEnumList = BusinessDetailTabEnum.getByBusinessTypeAndPermission(businessType, userVO.getPermSet());
        } else {
            tabEnumList = BusinessDetailTabEnum.getByBusinessTypeAndPermissionForDingtalk(businessType, userVO.getPermSet());
        }
        List<DetailTabPojo> tabList = new ArrayList<>();
        for (BusinessDetailTabEnum tabEnum : tabEnumList) {
            DetailTabPojo detailTabPojo = new DetailTabPojo();
            BeanUtil.copyProperties(tabEnum.getAnEnum(), detailTabPojo);
            detailTabPojo.setAttr(detailTabPojo.getKey());
            tabList.add(detailTabPojo);
        }
        return tabList;
    }
}
